import request from "../util/request.ts";
import { Device } from "./type/model.ts";

// 获取设备类型分页数据
export const fetchDevicePage = async (currentPage: number, pageSize: number, device: Partial<Device>, during: string[]): Promise<any> => {
    return await request.get(`/device/page`, {
        params: {
            currentPage,
            pageSize,
            device: JSON.stringify(device),
            during: during ? during.join(',') : []
        }
    });
}

// 添加设备类型
export const postDevice = async (device: Device): Promise<any> => await request.post("/device", device);

// 更新设备类型
export const putDevice = async (device: Device): Promise<any> => await request.put("/device", device);

// 删除设备类型
export const delDevice = async (id: number): Promise<any> => await request.delete(`/device/${id}`);

// 批量删除设备类型
export const batchDelDevice = async (ids: number[]): Promise<any> => await request.delete("/device/batch/delete", {
    params: {
        ids: ids.join(',')
    }
});

// 导出设备类型数据
export const exportDeviceData = async (): Promise<any> => await request.get("/device/export", { responseType: "blob" });

// 获取设备类型信息
export const fetchDeviceInfo = async (): Promise<any> => await request.get("/device/info");

// 根据ID获取设备类型
export const fetchDeviceById = async (id: number): Promise<any> => {
    return await request.get(`/device/${id}`);
}
